package com.dsbj.mp.icardservice.controller.companybus;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsbj.mp.icardservice.entity.companybus.Passenger;
import com.dsbj.mp.icardservice.utils.strprocess.Time_convert;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 公司班车》输出服务类。
 * @author cjw 2020-02-25
 */
@Service
@Transactional
public class OutputCompanyBus {
	
	
	/**
	 * 输出passenger信息。
	 * @param
	 * @return
	 * @author cjw 2020-02-26
	 */
	public static Map<String,Object> generatePassenger(Passenger passenger){
		if(passenger==null){
			return null;
		}
		Map<String,Object> mapPassenger=new LinkedHashMap<>();
		mapPassenger.put("passengerId",passenger.getId());
		mapPassenger.put("busno",passenger.getBusno());
		mapPassenger.put("busname",passenger.getCompanyBus()==null? null: passenger.getCompanyBus().getBusname());
		mapPassenger.put("licensePlateNum",passenger.getCompanyBus()==null? null: passenger.getCompanyBus().getLicensePlateNum());
		mapPassenger.put("createTime", Time_convert.convert_toStrWithoutSec(passenger.getCreateTime()));
		return mapPassenger;
	}
	
	/**
	 * 输出passenger信息。
	 * @param
	 * @return
	 * @author cjw 2020-02-25
	 */
	public static List<Map<String,Object>> generatePassenger(List<Passenger> list_passenger){
		if(list_passenger==null){
			return null;
		}
		List<Map<String,Object>> list_mapPassenger=new ArrayList<>();
		Map<String,Object> mapPassenger=null;
		
		for(Passenger passenger: list_passenger){
			mapPassenger=generatePassenger(passenger);
			list_mapPassenger.add(mapPassenger);
		}
		return list_mapPassenger;
	}
	
	/**
	 * 分页输出passenger信息。
	 * @param
	 * @return
	 * @author cjw 2020-02-25
	 */
	public static Page<Map<String,Object>> generatePassengerByPage(Page<Passenger> page){
		if(page==null||page.getRecords()==null){
			return (Page<Map<String, Object>>)(Page)page;
		}
		List<Map<String,Object>> list_mapPassenger=generatePassenger(page.getRecords());
		Page<Map<String,Object>> pageReturn= ((Page<Map<String,Object>>)(Page)page).setRecords(list_mapPassenger);
		return pageReturn;
	}
	







}
